<template>
  <el-container ref="homePage" :height="clientHeight">
    <el-header
      style="
        text-align: right;
        padding: 0;
        height: 60px;
        line-height: 60px;
        background-color: #3c8dbc;
        color: #fff;
      "
    >
      <a
        href="#/"
        style="
          text-decoration: none;
          text-align: center;
          width: 150px;
          height: 100%;
          float: left;
          background-color: #367fa9;
          color: #fff;
          border: none;
        "
      >
        <b style="font-weight: 800">h5-</b>
      </a>
      <el-dropdown trigger="click">
        <i
          class="el-icon-setting"
          style="color: #fff; cursor: pointer; margin-right: 10px"
        >
          {{ username }}</i
        >
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="showResetPwd"
            >修改密码</el-dropdown-item
          >
          <el-dropdown-item @click.native="logout">登出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-header>
    <el-container>
      <el-aside width="150px">
        <el-menu
          router
          :default-active="defaultActive"
          style="height: 100%"
          background-color="#1e282c"
          text-color="#8aa4af"
          active-text-color="#fff"
          class="el-menu-demo"
        >
          <el-menu-item index="/" class="el-menu-demo">
            <i class="el-icon-video-camera"></i>
            <span slot="title">流进程</span>
          </el-menu-item>
        </el-menu></el-aside
      >
      <el-container ref="pageContent">
        <el-scrollbar style="height: 100%; width: 100%">
          <el-backtop target=".el-scrollbar__wrap"></el-backtop>
          <router-view></router-view>
        </el-scrollbar>
      </el-container>
    </el-container>
    <ResetPwd
      :resetPwdVisible="resetPwdVisible"
      @hideResetPwd="hideResetPwd"
      @logout="logout"
    ></ResetPwd>
  </el-container>
</template>

<script>
import ResetPwd from "./page/user/ResetPwd";

export default {
  name: "Home",
  data() {
    return {
      username: "",
      role: "1",
      clientHeight: `${document.body.clientHeight}`,
      resetPwdVisible: false,
    };
  },
  components: { ResetPwd },
  methods: {
    logout() {
      this.$cookies.remove("_t");
      this.$cookies.remove("u");
      this.$cookies.remove("r");
      this.$router.replace({ path: "/login" });
    },
    showResetPwd() {
      this.resetPwdVisible = true;
    },
    hideResetPwd() {
      this.resetPwdVisible = false;
    },
  },
  mounted() {
    let _t = this.$cookies.get("_t");
    if (!_t || _t == "") {
      this.$message.error("token expired");
      this.$router.replace({ path: "/login" });
    }

    this.username = this.$cookies.get("u");
    this.role = this.$cookies.get("r");

    this.clientHeight = document.body.clientHeight;
    const _this = this;
    window.onresize = function temp() {
      _this.clientHeight = document.body.clientHeight;
    };
  },
  watch: {
    clientHeight: function (val) {
      this.$refs.homePage.$el.style.height = val + "px";
      this.$refs.pageContent.$el.style.height = val - 60 + "px";
    },
  },
  computed: {
    defaultActive() {
      return this.$route.path;
    },
  },
};
</script>

<style scoped>
.el-menu-demo {
  min-width: 150px;
  max-width: 150px;
  padding-right: 0px;
  border-right: solid 0px #e6e6e6;
}
</style>
